package com.quectel.business.common.parking;

import com.quectel.business.common.parking.charging.BaseOrderChargingCalc;
import com.quectel.core.module.device.service.DeviceService;
import com.quectel.core.module.device.service.DeviceTypeService;
import com.quectel.core.module.parking.dto.ParkingChargingDto;
import com.quectel.core.module.parkingcard.service.ParkingCardMemberDeviceService;
import com.quectel.core.module.parkingcard.service.ParkingCardMemberService;
import com.quectel.core.module.parkingcard.service.ParkingCardOrderDeviceService;
import com.quectel.core.module.parkingcard.service.ParkingCardOrderService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.util.Date;
import java.util.Objects;

@Component
@Slf4j
public class ParkingBusiness{
    @DubboReference
    private ParkingCardOrderService parkingCardOrderService;
    @DubboReference
    private DeviceService deviceService;
    @DubboReference
    private DeviceTypeService deviceTypeService;
    @DubboReference
    private ParkingCardOrderDeviceService parkingCardOrderDeviceService;
    @DubboReference
    private ParkingCardMemberService parkingCardMemberService;
    @DubboReference
    private ParkingCardMemberDeviceService parkingCardMemberDeviceService;

    /**
     *
     * @param parkingCharging 收费配置
     * @param startTime 开始时间
     * @param endTime 截止时间
     * @return
     */
    public BigDecimal calAmount(ParkingChargingDto parkingCharging, Date startTime, Date endTime){
        BaseOrderChargingCalc baseOrderChargingCalc = BaseOrderChargingCalc.getCalcByType(parkingCharging.getType());
        if (Objects.isNull(baseOrderChargingCalc)) {
            throw new IllegalArgumentException("Parking charging config error.");
        }
        return baseOrderChargingCalc.calc(startTime, endTime, parkingCharging);
    }




}
